set more off
clear
cd "D:\Projects\HeterogeneousExternalities\Data\"



use Daily_Data.dta,clear

*Make categorical regulatory variable that will display county's most stringent regulation.
gen regulation=1 if yes_RVP9==1
replace regulation=2 if yes_RVP78==1
replace regulation=3 if yes_RVP7==1
replace regulation=4 if yes_RFG==1

duplicates drop county_fips regulation, force
save "Maps\RegMapData.dta",replace
cd "D:\Projects\HeterogeneousExternalities\Data\Maps"
shp2dta using "cb_2017_us_state_500k", database(usdb_state) coordinates(uscoord_state) genid(id) replace
shp2dta using "cb_2017_us_county_500k",database(usdb_county) coordinates(uscoord_county) genid(id) gencentroids(center) replace

use usdb_state,clear

destring STATEFP,gen(fip_byte)
statastates, fips(fip_byte) 
keep if _merge==3
drop if state_abbrev=="HI" 
drop if state_abbrev=="AK"

save usdb_state,replace



use usdb_county,clear


gen county_fips=STATEFP+COUNTYFP
merge 1:1 county_fips using RegMapData.dta,nogen


destring STATEFP,gen(fip_byte)
statastates, fips(fip_byte) 
keep if _merge==3
drop if state_abbrev=="HI"
drop if state_abbrev=="AK"

drop if regulation==.
spmap regulation using uscoord_county,id(id) fcolor(YlGnBu) clmethod(unique) clbreaks(1 2 3 4) ///
	ndocolor(none) ndsize(none) ///
	legend(label(2 "RVP 9.0") label(3 "RVP 7.8") label(4 "RVP 7.0") label(5 "RFG") label(1 "") pos(4) size(large))  ///
	polygon(data(uscoord_state) ///
	select(drop if _ID==19 | _ID==39 | _ID==42 | _ID==46 | _ID==52 | _ID==17 | _ID==56))

cap erase usdb_county.dta
cap erase usdb_state.dta
cap erase uscoord_state.dta
cap erase uscoord_county.dta
